class Solution
{
public:
    int countNicePairs(vector<int> &nums)
    {
        unordered_map<int, int> numMinusRevCount;
        int result = 0;
        for (int num : nums)
        {
            int numMinusRev = num - rev(num);
            result += numMinusRevCount[numMinusRev];
            result %= 1000000007;
            ++numMinusRevCount[numMinusRev];
        }
        return result;
    }

    int rev(int x)
    {
        int result = 0;
        while (x)
        {
            result *= 10;
            result += x % 10;
            x /= 10;
        }
        return result;
    }
};